# -*- coding: utf-8 -*-
# @Time    : 2022/5/19 18:43
# @Author  : 我还能卷
# @FileName: use_excel.py
# @Software: PyCharm

import openpyxl
from openpyxl.worksheet.worksheet import Worksheet

# 得到的每行数据都是元组


def read_excel1(path, sheet_name):

    f = openpyxl.load_workbook(path)
    sheet: Worksheet = f[sheet_name]
    rows = list(sheet.values)
    return rows[1:]

# 得到数据为字典


def read_excel2(path, sheet_name):
    f = openpyxl.load_workbook(path)
    sheet: Worksheet = f[sheet_name]
    rows = list(sheet.values)
    title = rows[0]
    rows1 = rows[1:]
    new = [dict(zip(title, row)) for row in rows1]
    return new

# 使用for循环实现


def read_excel3(path, sheet_name):
    f = openpyxl.load_workbook(path)
    sheet: Worksheet = f[sheet_name]
    rows = list(sheet.values)
    title = rows[0]
    rows = rows[1:]
    list1 = list()

    for row in rows:
        dict1 = dict()
        for k, v in enumerate(row):
            dict1[title[k]] = v
        # print(dict1)
        list1.append(dict1)
    return list1


result = read_excel3('testcase.xlsx', '后台注册')
print(result)
